#系统随机生成8个1-33的整数形成一注中奖号码，用户在控制台输入8位数字看是否中奖

import random
# 生成中奖号码
winning_numbers = random.sample(range(1, 34), 8);
# 判断中奖等级函数
def check_prize(input_numbers):
    correct_count = 0;
    for number in input_numbers:
        if number in winning_numbers:
            correct_count += 1;
    if correct_count == 8:
        return 1;
    elif correct_count == 7:
        return 2;
    elif correct_count == 6:
        return 3;
    elif correct_count == 5:
        return 4;
    else:
        return 0;
# 模拟随机购买10000注彩票对特定号码的中奖概率
def simulate_lottery(target_numbers):
    total_count = 10000;
    one_prize_count = 0;
    two_prize_count = 0;
    three_prize_count = 0;
    four_prize_count = 0;
    for i in range(total_count):
        input_numbers = random.sample(range(1, 34), 8);
        prize_level = check_prize(input_numbers);
        if prize_level == 1:
            one_prize_count += 1;
        elif prize_level == 2:
            two_prize_count += 1;
        elif prize_level == 3:
            three_prize_count += 1;
        elif prize_level == 4:
            four_prize_count += 1;
    print("中奖号码为：", winning_numbers);
    print(f"模拟{total_count}注彩票，其中{one_prize_count}注中了一等奖，中奖概率为{one_prize_count/total_count:.2%}")
    print(f"其中{two_prize_count}注中了二等奖，中奖概率为{two_prize_count/total_count:.2%}")
    print(f"其中{three_prize_count}注中了三等奖，中奖概率为{three_prize_count/total_count:.2%}")
    print(f"其中{four_prize_count}注中了四等奖，中奖概率为{four_prize_count/total_count:.2%}")
    # 统计目标号码中奖情况
    target_count = 0;
    for i in range(total_count):
        input_numbers = random.sample(range(1, 34), 8);
        if set(target_numbers) == set(input_numbers):
            target_count += 1;
    print(f"模拟{total_count}注彩票，其中{target_count}注中了目标号码，中奖概率为{target_count/total_count:.2%}")
# 测试
target_numbers = [1, 2, 3, 4, 5, 6, 7, 8];
simulate_lottery(target_numbers);
